package cn.imvc.app.controllers.goods;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Goods;
import cn.imvc.app.entities.GoodsPrice;
import cn.imvc.app.entities.GoodsSku;
import cn.imvc.app.entities.PriceClass;
import cn.imvc.app.models.GoodsPriceModel;
import cn.imvc.app.models.LoggingModel;
import cn.imvc.app.models.PriceClassModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class GoodsPriceControllerImpl implements GoodsPriceController {
	static Logger logger = Logger.getLogger(GoodsPriceControllerImpl.class);
	
	@Autowired
	PriceClassModel priceClassModel;
	@Autowired
	GoodsPriceModel goodsPriceModel;
	@Autowired
	LoggingModel loggingModel;
	
	public GoodsSku goodsSku;
	public PriceClass priceClass;
	public List<GoodsPrice> goodsPrices;
	public List<Double> prices;
	public int goodsId;
	public int goodsSkuId;
	
	public void setPrices(List<Double> prices) {
		this.prices = prices;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public void setGoodsSkuId(int goodsSkuId) {
		this.goodsSkuId = goodsSkuId;
	}
	
	public void setGoodsPrices(List<GoodsPrice> goodsPrices) {
		this.goodsPrices = goodsPrices;
	}

	public String search() {
		// TODO Auto-generated method stub
		return null;
	}

	public String index() {
		//当不存在商品价格时，插入商品价格空记录
		goodsSku = new GoodsSku();
		goodsSku.setId(goodsSkuId);
		Goods goodsTmp = new Goods();
		goodsTmp.setId(goodsId);
		goodsSku.setGoods(goodsTmp);
		goodsPriceModel.updateEmptyPrice(goodsSku);
		goodsPrices = goodsPriceModel.findCurSkuPrice(goodsSku);
		return "goods-price/index";
	}

	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

	public String editNew() {
		// TODO Auto-generated method stub
		return null;
	}

	public String create() {
		// TODO Auto-generated method stub
		return null;
	}

	public String edit() {
		// TODO Auto-generated method stub
		return null;
	}

	public String update() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroyBatch() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public String updatePrice(){
		goodsPriceModel.updatePriceBatch(goodsPrices,prices,goodsId);
		return Render.json(new DialogBean("200", "更新成功","goods_sku", "closeCurrent"));
	}

}
